class UserInfo {
  static STORAGE_KEY = "userinfo";
  _userInfo = null;
  // 代理模式
  constructor() {
    if (typeof UserInfo.instance === "object") {
      return UserInfo.instance;
    }
    UserInfo.instance = this;
    return this;
  }

  removeUserInfo() {
    this._userInfo = null;
    wx.setStorageSync(UserInfo.STORAGE_KEY, null);
  }

  setUserInfo(userInfo) {
    this._userInfo = userInfo;
    wx.setStorageSync(UserInfo.STORAGE_KEY, userInfo);
  }

  getUserInfo() {
    if (this._userInfo !== null) {
      return this._userInfo;
    }
    let userInfo = wx.getStorageSync(UserInfo.STORAGE_KEY);
    this._userInfo = userInfo;
    return userInfo;
  }
}
export { UserInfo };
